<?php

namespace Admin\Controller;

use Think\Controller;

class ProjectSeeController extends BaseController
{
    public function index()
    {
        if (IS_POST) {

            $tea = M('projecttask');
            if (!isset($_POST['page']) || empty($_POST['page'])) {
                $page = 1;
            } else {
                $page = $_POST['page'];
            }
            if (!isset($_POST['limit']) || empty($_POST['limit'])) {
                $limit = 10;
            } else {
                $limit = $_POST['limit'];
            }
            // $condition['is_del'] = 0;
            if (isset($_POST['search'])) {
                $condition[] = [
                    'project_id' => array('like', "%" . $_POST['search'] . "%"),
                    'project_topic' => array('like', "%" . $_POST['search'] . "%"),
                    'teacher_id' => array('like', "%" . $_POST['search'] . "%"),
                    'teacher_name' => array('like', "%" . $_POST['search'] . "%"),
                    'student_name' => array('like', "%" . $_POST['search'] . "%"),
                    'term' => array('like', "%" . $_POST['search'] . "%"),
                    '_logic' => 'OR',
                ];
            }
            //添加删除字段
            $count = $tea->where($condition)->count();
            $data = $tea->where($condition)->page($page, $limit)->select() ?: [];
            
            return $this->successResponse('获取成功', $data, $count);
        } else {
            $this->display();
        }
    }
}

